package com.zpp.common.core.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.github.pagehelper.PageInfo;
import com.zpp.common.core.domain.Result;
import com.zpp.common.core.domain.TableDataInfo;

import java.util.List;

public class BaseController {

    public Result toResult(int rows) {
        return rows > 0 ? Result.success() : Result.fail();
    }

    public Result toResult(boolean ret) {
        return ret ? Result.success() : Result.fail();
    }


    public TableDataInfo getTableDataInfo(List<?> list) {
        if(CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        //获取符合条件查询的总数
        return TableDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}
